<% layout('/layout/default.html', {title: '发起任务', libs: ['dataGrid', 'icheck']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="card-header">
			<i class="fa fa-sitemap"></i> 发起流程
			<div class="header-tools float-right">
				<a href="#" class="btn btn-default btn-sm" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
			</div>
		</div>
		<div class="container-fluid">
			<form id="searchForm" action="${ctx}/act/flowForm/processDataList" class="form-inline d-none">
				<div class="form-group">
					<label class="control-label">流程分类：</label>
					<div class="control-inline">
						<#form:select path="category" name="label" data="getDictList:act_category" class="form-control select2bs4" />
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-success btn-sm">查询</button>
					<button id="reset" type="reset" class="btn btn-default btn-sm">重置</button>
				</div>
			</form>
			<table id="dataGrid"></table>
		</div>
	</div>
</div>
<% } %>
<script>
	$.fn.select2.defaults.set('width', '200px');
	$('#reset').click(function(){
		$('#category').val(null).trigger("change");
	});
	//初始化DataGrid对象
	$('#dataGrid').dataGrid({
		searchForm: $("#searchForm"),
		columnModel: [
			{header:'流程分类', name:'categoryName', index:'categoryName', width:90, align:"center"},
			// {header:'流程标识', name:'key', index:'key', width:90, align:"center"},
			{header:'流程名称', name:'name', index:'name', width:100, align:"center" },
			//{header:'流程资源', name:'proceDefResName', index:'proceDefResName', width:100, align:"center" },
			// {header:'流程图', name:'diagramResourceName', index:'', width:100, align:"center",formatter: function(val, obj, row, act){
			// 	return '<a href="${ctx}/act/process/resource/read?procDefId='+row.id+'&resType=image"  class="btnList" title="流程图查看" data-type="diagram" >'+val+'</a>';
			//
			// } },
			{header:'流程版本', name:'version', index:'version', width:80, align:"center",formatter: function(val, obj, row, act){
					return 'V:'+val;
				} },
			{header:'操作', name:'actions', width:100, sortable:false, title:false, align:"center",formatter: function(val, obj, row, act){
					var actions = [];
				<% if(hasPermi('act:process:edit')){ %>
						actions.push('<a href="javascript:void(0);" onclick="checkExit(\''+ row.id + '\',\''+ row.key +'\')" title="发起流程" ><i class="far fa-paper-plane"></i>&nbsp;</a>');
					<% } %>
					return actions.join('');
				}}
		],
		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});
</script>


<script type="text/javascript">

	function checkExit(procDefId, procDefKey) {

		startFlow(procDefId, procDefKey);

		/*js.ajaxRequest('/jsite/a/act/flowForm/checkFlowExit', {'procDefKey':procDefKey}, function (data) {
			if (data.result == "true") {
				js.confirm("您有未完成的绩效流程，不能再次发起！", function () {});
			} else {
				startFlow(procDefId, procDefKey);
			}
		});*/
	}

	function startFlow(procDefId, procDefKey) {
		var url = '/act/flowForm/common?procDefId='+procDefId+'&procDefKey='+ procDefKey;
		var title = '发起流程';

		js.ajaxRequest('/jsite/a/act/flowForm/hasTemp', {'procDefKey':procDefKey}, function (data) {
			if (data.result == "true") {
				js.layer.confirm('检测到您有尚未提交的流程，您可以 [继续编辑] 或者 [重新发起] 。 注意：选择重新发起，将会删除缓存数据。',
						{icon: 3, shadeClose: true, btn: ['继续编辑','重新发起']}, function(index) {
							addTabPage(title, url);
							js.layer.close(index);
						}, function(index){
							js.ajaxRequest('/jsite/a/act/flowForm/delTemp', {'procDefKey':procDefKey}, function (data) {
								addTabPage(title, url);
							});
							js.layer.close(index);
						});
			} else {
				addTabPage(title, url);
			}
		});
	}

	function addTabPage(title, url) {
		var win;
		if (window.tabpanel) {
			win = window;
		}
		if (parent.tabpanel) {
			win = window.parent;
		}
		if (parent.parent.tabpanel) {
			win = window.parent.parent;
		}
		if (top.tabpanel) {
			win = top;
		}
		win.addTabPage(null, title, url, true, true);
	}


</script>